<?php
/*
	首页
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
set_html('header','common/header-cms');
$return['pcd']=$_SESSION['pcd']?:array();
$_SESSION['area_code']=$_RQ['area_code']?:$_SESSION['area_code'];
$return['area_code']=$_SESSION['area_code'];
if($_RQ['op']=='main'){
	
	$return['list']=array();
	$return['indexpai']=array();
	$setting = plugin('jy_weishop')->plugin_setting('setting');
	if(!$setting['issearch']){
		$return['indexpai'][]=array('name'=>'search');
	}
	$return['indexpai'][]=array('name'=>'notice');
	if(!$setting['isshare']){
		$return['indexpai'][]=array('name'=>'share');
	}
	if(!$setting['no_ordermodal']){
		$return['indexpai'][]=array('name'=>'ordermodal');
	}
	$p_group=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'isrecommand'=>'1','isshow'=>'1','parentid'=>'0'),'','paixu asc');
	//子分类
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	$params['saletype likes']=array('1');
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','title','image','price','total','active_plugin','active_id');
	if($p_group){
		$i=0;
		foreach($p_group as &$item){
			$item['c_group']=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>'1','isrecommand'=>'1','parentid'=>$item['id']),'','paixu asc');
			$item['goodslist']=pdo_getslice('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'saletype likes'=>array('1'),'pcate'=>$item['id']),array($pindex,$psize),$total,$fields,'','paixu desc');
			$item['goodsnew']=pdo_getslice('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'saletype likes'=>array('2'),'pcate'=>$item['id']),array($pindex,$psize),$total,$fields,'','paixu desc');
			$i=$i+1;
			$item['i']=$i;
			if($item['c_group']){
				foreach($item['c_group'] as &$row){
					$params['ccate']=$row['id'];
					$row['goods']=pdo_getslice('jy_weishop_goods',$params,array($pindex,$psize),$total,$fields,'','paixu desc');
				}
			}
		}
	}
	$parameter=array(
		//'table'=>'jy_weishop_goods',
		'fields'=>array('id','title','image','marketprice','price','total','salenum','pluginname'),
		'orderby'=>'paixu desc',
		'limit'=>'5',
	);
	//热卖
	$parameter['params']=array('saletype likes'=>array('3'),'pluginname'=>array('jy_jdk','jy_taobaoke','jy_pddke'),'uniacid'=>$_SESSION['uniacid'],'status'=>1);
	$hot_list=model('jy_weishop/goods')->goods_list($parameter);
	//公告列表
	$notice_list = pdo_fetchall('SELECT * FROM ' . tablename('jy_weishop_notice') . ' WHERE uniacid=:uniacid AND status=1  ORDER BY id DESC limit 4', array(':uniacid' => $_SESSION['uniacid']));
	if($notice_list){
		foreach($notice_list as &$notice){
			$notice['createtime']=date('Y-m-d h:i',$notice['createtime']);
		}
	}
	//今日数据
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$return['delfee']=pdo_getsum('jy_weishopke_order',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$daytime),'total_price');
	$return['delfee']=price($return['delfee']*0.13,true);
	//获取用户信息
	$return['extradata']=array();
	$return['user']=model('core/member')->basic($_SESSION['uid']);
	$return['login']=$_SESSION['uid']?1:2;
	$return['hot_list']=$hot_list;
	$return['notice_list']=$notice_list;
	$return['p_group']=$p_group;
	$return['params']['pid']=0;
	$return['sharedata']=array(
		'title'=>$return['pluginset']['share_title']?$return['pluginset']['share_title']:'首页-在线商城',
		'desc'=>$return['pluginset']['share_desc']?$return['pluginset']['share_desc']:'在线商城，一个属于自己的个人商城！',
		'link'=>custom_url('jy_weishopke/index//fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>ATTACHMENT_URL.$return['pluginset']['share_image']
	);
	//刷新当前用户地址
	if(($_SESSION['pcd'] && $_SESSION['pcd']['city']) || $_SESSION['area_code']){
		if(!$_SESSION['area_code']){
			$return['area_code']=$_SESSION['area_code']=$return['store']['area_code'];
			$return['store']['members']=pdo_count('jy_weishop_member',array('area_code'=>$return['store']['area_code']),'id');
			$return['store']['salenum']=pdo_getsum('jy_weishop_order',array('area_code'=>$return['store']['area_code']),'ispay');
		}else{
			$return['store']['members']=pdo_count('jy_weishop_member',array('area_code'=>$_SESSION['area_code']),'id');
			$return['store']['salenum']=pdo_getsum('jy_weishop_order',array('area_code'=>$_SESSION['area_code']),'ispay');
		}
		$return['pluginset']['title']=$return['pluginset']['title']?:'在线商城，精品优选';
		$return['sharedata']=array(
			'title'=>$return['store']['title'].$return['pluginset']['title'],
			'desc'=>$return['pluginset']['desc']?:'在线购物，让温度传递！',
			'link'=>custom_url('jy_weishopke/index//area_code='.$return['store']['area_code'].'&fromuser='.$_SESSION['uid'],true),
			'imgUrl'=>$return['pluginset']['share_image']?ATTACHMENT_URL.$return['pluginset']['share_image']:ATTACHMENT_URL.'../addons/jy_shopyouone/resource/images/storelogo.jpg',
		);
	}
	set_html('title',$return['pluginset']['title']?'首页-'.$return['pluginset']['title']:'首页-在线商城');	
	if(empty($return['orderlist'])){
		$return['coupon_wait']=model('jy_weishop/task')->pop_coupon_wait();
		if(!$return['coupon_wait']){
			$return['coupon_hd']=model('jy_weishop/task')->pop_coupon_hd();
			if(!$return['coupon_hd']){
				$return['game_wait']=model('jy_weishop/task')->pop_game();
			}
		}
	}
	exi($return);
}
	
?>